﻿<%@ Page Title="AGR: Courses" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Courses.aspx.cs" Inherits="AGR.Web.Pages.Courses.Courses" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>

<%@ Register TagPrefix="uc" TagName="CourseDetail" Src="~/Controls/Form/DetailForm/CourseDetail.ascx" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="RightContent" runat="server">
</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">

    <h3>Courses</h3>
    <hr />

    <asp:UpdatePanel ID="CoursesUpdatePanel" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
     
        <table>
            <tr>
                <td>Search:</td>
                <td>
                    <asp:TextBox ID="txtSearch" runat="server" CssClass="textbox-small"></asp:TextBox>
                </td>
                <td>
                    <asp:Button ID="btnSearch" runat="server" Text="Search" CssClass="button" 
                        onclick="btnSearch_Click" />
                    <asp:Button ID="btnSearchClear" runat="server" Text="Clear" CssClass="button"
                         OnClick="btnSearchClear_Click" />
                </td>
            </tr>
        </table>

        <br />

        <table>
            <tr>
                <td>
                    <asp:Button ID="btnAdd" runat="server" Text="Add" CssClass="button"
                        onclick="btnAdd_Click" />
                    <asp:Button ID="btnDelete" runat="server" Text="Remove" CssClass="button"
                     OnClick="btnDelete_Click" />
                </td>
            </tr>
            <tr>
                <td>
                    <asp:GridView ID="CourseGridView" runat="server" CssClass="table-grid" AlternatingRowStyle-CssClass="odd" FooterStyle-CssClass="table-grid-footer"
                    EmptyDataRowStyle-CssClass="empty" EmptyDataText="No courses found." PagerStyle-CssClass="pager"
                    DataKeyNames="CourseCode"
                    AutoGenerateColumns="False" 
                    onrowcommand="CourseGridView_OnRowCommand" 
                    OnSelectedIndexChanging="CourseGridView_SelectedIndexChanging"
                    onrowcancelingedit="CourseGridView_RowCancelingEdit" 
                    onrowediting="CourseGridView_RowEditing" 
                    onrowupdating="CourseGridView_RowUpdating" 
                    onpageindexchanging="CourseGridView_PageIndexChanging"
                    AllowPaging="True" PageSize="10">
                        <PagerSettings Mode="NumericFirstLast" Position="Bottom"/>
                        <Columns>
                            <asp:TemplateField HeaderText="Select" HeaderStyle-Width="40px" 
                             HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" FooterStyle-HorizontalAlign="Center">
                                <ItemTemplate>
                                    <asp:CheckBox ID="chkSelect" runat="server" CausesValidation="False"> </asp:CheckBox>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:CheckBox ID="chkSelect" runat="server" Enabled="false" CausesValidation="False"> </asp:CheckBox>
                                </EditItemTemplate>
                                <FooterTemplate>
                                    <strong>Add</strong>
                                </FooterTemplate>
                            </asp:TemplateField>

                            <asp:TemplateField HeaderText="Options" HeaderStyle-Width="80px" HeaderStyle-HorizontalAlign="Center">
                                <ItemTemplate>
                                    <asp:LinkButton ID="lnkCourseDetails" runat="server" CausesValidation="False" Text="Details" CommandName="Select" />
                                    &nbsp;
                                    <asp:LinkButton ID="lnkCourseEdit" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit" />
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:LinkButton ID="lnkCourseCancel" runat="server" CausesValidation="False"  CommandName="Cancel" Text="Cancel"></asp:LinkButton>
                                    &nbsp;
                                    <asp:LinkButton ID="lnkCourseUpdate" runat="server" CausesValidation="True" CommandName="Update" Text="Update"
                                        ValidationGroup="CourseUpdateValidationGroup"></asp:LinkButton>
                                </EditItemTemplate>
                                <FooterTemplate>
                                    <asp:LinkButton ID="btnCourseCancel" runat="server" Text="Cancel" CausesValidation="false" UseSubmitBehavior="false" CommandName="CancelInsert" />
                                    &nbsp;
                                    <asp:LinkButton ID="btnCourseInsert" runat="server" Text="Save" UseSubmitBehavior="false" CommandName="Insert"
                                        ValidationGroup="CourseSaveValidationGroup" />
                                </FooterTemplate>
                            </asp:TemplateField>

                            <asp:TemplateField HeaderText="Course Code" HeaderStyle-Width="90px">
                                <ItemTemplate><%# Eval("CourseCode")%></ItemTemplate>
                                <EditItemTemplate>
                                    <asp:TextBox ID="txtCourseCode" runat="server" Text='<%# Eval("CourseCode")%>' Width="80px" Enabled="false"></asp:TextBox>
                                    <asp:RequiredFieldValidator ControlToValidate="txtCourseCode" ID="CourseCodeValidator" runat="server" ErrorMessage=" * " 
                                        Display="Dynamic" CssClass="ClassValidator" ValidationGroup="CourseUpdateValidationGroup" ></asp:RequiredFieldValidator>
                                </EditItemTemplate>
                                <FooterTemplate>
                                    <asp:TextBox ID="txtCourseCode" runat="server" Width="80px"></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="CourseCodeValidator" runat="server" ErrorMessage=" * " Display="Dynamic" CssClass="ClassValidator"
                                        ControlToValidate="txtCourseCode" ValidationGroup="CourseSaveValidationGroup"></asp:RequiredFieldValidator>
                                </FooterTemplate>
                            </asp:TemplateField>

                            <asp:TemplateField HeaderText="Course" HeaderStyle-Width="220px">
                                <ItemTemplate><%# Eval("CourseName")%></ItemTemplate>
                                <EditItemTemplate>
                                    <asp:TextBox ID="txtCourseName" runat="server" Text='<%# Eval("CourseName")%>' Width="210px"></asp:TextBox>
                                    <asp:RequiredFieldValidator ControlToValidate="txtCourseName" ID="CourseNameValidator" runat="server" ErrorMessage=" * " 
                                        Display="Dynamic" CssClass="ClassValidator" ValidationGroup="CourseUpdateValidationGroup" ></asp:RequiredFieldValidator>
                                </EditItemTemplate>
                                <FooterTemplate>
                                    <asp:TextBox ID="txtCourseName" runat="server" Width="210px"></asp:TextBox>
                                    <asp:RequiredFieldValidator ControlToValidate="txtCourseName" ID="CourseNameValidator" runat="server" ErrorMessage=" * " 
                                        Display="Dynamic" CssClass="ClassValidator"  ValidationGroup="CourseSaveValidationGroup" ></asp:RequiredFieldValidator>
                                </FooterTemplate>
                            </asp:TemplateField>

                            <asp:TemplateField HeaderText="Accreditation" HeaderStyle-Width="100px">
                                <ItemTemplate><%# Eval("AccreditationNumber")%></ItemTemplate>
                                <EditItemTemplate>
                                    <asp:TextBox ID="txtAccreditationNumber" runat="server" Text='<%# Eval("AccreditationNumber")%>' Width="90px"></asp:TextBox>
                                    <asp:RequiredFieldValidator ControlToValidate="txtAccreditationNumber" ID="AccreditationNumberValidator" runat="server" ErrorMessage=" * " 
                                        Display="Dynamic" CssClass="ClassValidator" ValidationGroup="CourseUpdateValidationGroup" ></asp:RequiredFieldValidator>
                                </EditItemTemplate>
                                <FooterTemplate>
                                    <asp:TextBox ID="txtAccreditationNumber" runat="server" Width="90px"></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="AccreditationNumberValidator" runat="server" ErrorMessage=" * " Display="Dynamic" CssClass="ClassValidator"
                                        ControlToValidate="txtAccreditationNumber"  ValidationGroup="CourseSaveValidationGroup"></asp:RequiredFieldValidator>
                                </FooterTemplate>
                            </asp:TemplateField>

                            <asp:TemplateField HeaderText="Category" HeaderStyle-Width="100px">
                                <ItemTemplate><%# Eval("Category")%></ItemTemplate>
                                <EditItemTemplate>
                                    <asp:TextBox ID="txtCategory" runat="server" Text='<%# Eval("Category")%>' Width="90px"></asp:TextBox>
                                    <asp:RequiredFieldValidator ControlToValidate="txtCategory" ID="CategoryValidator" runat="server" ErrorMessage=" * " 
                                        Display="Dynamic" CssClass="ClassValidator" ValidationGroup="CourseUpdateValidationGroup" ></asp:RequiredFieldValidator>
                                </EditItemTemplate>
                                <FooterTemplate>
                                    <asp:TextBox ID="txtCategory" runat="server" Width="90px"></asp:TextBox>
                                    <asp:RequiredFieldValidator ControlToValidate="txtCategory" ID="CategoryValidator" runat="server" ErrorMessage=" * " 
                                        Display="Dynamic" CssClass="ClassValidator" ValidationGroup="CourseSaveValidationGroup" ></asp:RequiredFieldValidator>
                                </FooterTemplate>
                            </asp:TemplateField>

                            <asp:TemplateField HeaderText="Certificate" HeaderStyle-Width="120px">
                                <ItemTemplate><%# Eval("CertificateType")%></ItemTemplate>
                                <EditItemTemplate>
                                    <asp:TextBox ID="txtCertificateType" runat="server" Text='<%# Eval("CertificateType")%>' Width="110px"></asp:TextBox>
                                    <asp:RequiredFieldValidator ControlToValidate="txtCertificateType" ID="CertificateTypeValidator" runat="server" ErrorMessage=" * " 
                                        Display="Dynamic" CssClass="ClassValidator" ValidationGroup="CourseUpdateValidationGroup" ></asp:RequiredFieldValidator>
                                </EditItemTemplate>
                                <FooterTemplate>
                                    <asp:TextBox ID="txtCertificateType" runat="server" Width="110px"></asp:TextBox>
                                    <asp:RequiredFieldValidator ControlToValidate="txtCertificateType" ID="CertificateTypeValidator" runat="server" ErrorMessage=" * " 
                                        Display="Dynamic" CssClass="ClassValidator" ValidationGroup="CourseSaveValidationGroup" ></asp:RequiredFieldValidator>
                                </FooterTemplate>
                            </asp:TemplateField>
                        </Columns>
                        <PagerStyle HorizontalAlign="Right" Wrap="False" />
                    </asp:GridView>
                </td>
            </tr>
        </table>

        <asp:Panel ID="CourseDetailPanel" runat="server" style="display: none;">
            <div class="mypopup">
                <div class="header">
                    Course Details
                    <asp:ImageButton ID="btnCourseDetailClose" CausesValidation="false" CssClass="close" ImageUrl="~/Content/Images/Buttons/close-button.png" runat="server" />
                </div>
                <div class="content">
                    <uc:CourseDetail ID="ucCourseDetail" runat="server" />
                </div>
            </div>
        </asp:Panel>

        <asp:HiddenField ID="DummyTargetControlID" runat="server" />

        <ajaxToolkit:ModalPopupExtender
            BackgroundCssClass="modalpopup" 
            DropShadow="false"
            runat="server"
            CancelControlID="btnCourseDetailClose"
            TargetControlID="DummyTargetControlID"
            PopupControlID="CourseDetailPanel"
            id="CourseDetailModalPopupExtender" /> 

    </ContentTemplate>
    </asp:UpdatePanel>

</asp:Content>
